(function(win){
	function _createXMLHttpRequest() {
		var xhr = null;
		if(win.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if(win.ActiveXObject) {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} else {
			return null
		}
	}

	function _ajax(config) {
		var url = config.url,
				method = config.method || "GET",
				type = config.type || "text",
				isAsync = config.async || true,
				onSuccess = config.onSuccess || null,
				onError = config.onError || null,
				data = config.data;
		if(!url) {
			console.log("请输入url")
			return;
		}
		var xhr = _createXMLHttpRequest();
		if(xhr) {
			xhr.onreadystatechange = function() {
				var result = null;
				if(xhr.readyState == 4){
					result = type === 'text' ? xhr.responseText : xhr.responseXML;
					if((xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) 
						&& config['onSuccess']) {
							config['onSuccess'](result);
					} else {
							config['onError'](result);
					}
				} 
			}
			
			xhr.open(method, url, isAsync);

			xhr.send();
		} else {
			console.log("你的浏览器不支持Ajax");
		}

	}

	var weblib = {
		ajax: _ajax
	};
	
	return win.weblib ? win.weblib : win.weblib = weblib;
}(window));
